﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace StarLabel.label.item
{
    /// <summary>
    /// Copyright 2019  ZhengJi. All Rights Reserved.
    ///  标签定义基类
    /// </summary>
    public abstract class Item
    {

        public string X { get; set; }
        public string Y { get; set; }
        public string Width { get; set; }
        public string Height { get; set; }

        public string DataField { get; set; }
        public string Text { get; set; }
        public string Rotation { get; set; }

        protected XmlElement xmlEl { get; set; }
        public  Item(XmlElement el)
        {
            this.xmlEl = el;

            this.parseFromXml();
        }
        /// <summary>
        /// 子类重载此方法解析特定的属性。
        /// 子类方法应调用base.parseFromXml();
        /// 此方法已在构造函数中调用，无须单独调用
        /// </summary>
        protected virtual void parseFromXml()
        {
            this.X = this.xmlEl.Attributes["X"]==null?"": this.xmlEl.Attributes["X"].Value;
            this.Y = this.xmlEl.Attributes["Y"] == null ? "" : this.xmlEl.Attributes["Y"].Value;

            this.Width = this.xmlEl.Attributes["Width"] == null ? "" : this.xmlEl.Attributes["Width"].Value;
            this.Height = this.xmlEl.Attributes["Height"] == null ? "" : this.xmlEl.Attributes["Height"].Value;
            this.DataField = this.xmlEl.Attributes["DataField"] == null ? "" : this.xmlEl.Attributes["DataField"].Value;
            this.Text = this.xmlEl.Attributes["Text"] == null ? "" : this.xmlEl.Attributes["Text"].Value;
            this.Rotation = this.xmlEl.Attributes["Rotation"] == null ? "" : this.xmlEl.Attributes["Rotation"].Value;

        }

        /// <summary>
        /// 子类实现该方法打印条码
        /// </summary>
        /// <param name="x">x坐标，0：表示采用标签定义中X的值</param>
        /// <param name="y">y坐标，0：表示采用标签定义中Y的值</param>
        /// <param name="labelText">标签文本</param>
        /// <param name="rotation">反转角度,90,180,270</param>
        public abstract void DrawLabel(float x, float y,string labelText,string rotation);
    }
}
